﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyNetwork
{
    public class RVStatus
    {
        public RVStatus(string str_cmd)
        {
            _str_cmd = str_cmd;
        }

        private string _str_cmd = "WaferH";
        public string Command => _str_cmd;

        private Byte _seq = 0;
        public Byte Seq => _seq;

        public int SiteID = 0;
        public int MarkID1 = 0;
        public int Count1 = 0;

        public int MarkID2 = 0;
        public int Count2 = 0;


        //public string CMD => _str_cmd + ":" + _seq.ToString() + ":" + content + ":E#";
        public string CMD => _str_cmd + ":" + _seq.ToString() + ":"
            + SiteID.ToString() + ":"
            + MarkID1.ToString() + ":" + Count1.ToString() + ":"
            + MarkID2.ToString() + ":" + Count2.ToString() + ":"
            + content + ":E#";

        private string content = "";
        public string Content
		{
			get { return content; }
			set { content = value; }
		}

        public string NewCommand(string content_comma = "")
        {
            _seq++;
            content = content_comma;
            return _str_cmd + ":" + _seq.ToString() + ":"
            + SiteID.ToString() + ":" 
            + MarkID1.ToString() + ":" + Count1.ToString() + ":"
            + MarkID2.ToString() + ":" + Count2.ToString() + ":"
            + content + ":E#";
        }
        public string RespCommand(string content_comma = "")
        {
            content = content_comma;
            return _str_cmd + ":" + _seq.ToString() + ":"
            + SiteID.ToString() + ":" 
            + MarkID1.ToString() + ":" + Count1.ToString() + ":"
            + MarkID2.ToString() + ":" + Count2.ToString() + ":"
            + content + ":E#";
        }

        public bool Parse(string str_recv)
        {
            try
            {
                var ps = str_recv.Split(new char[] { ':' });
                if (ps.Length < 9)
                {
                    return false;
                }
                _str_cmd = ps[0];
                _seq = Convert.ToByte(ps[1]);

                SiteID = Convert.ToInt32(ps[2]);
                MarkID1 = Convert.ToInt32(ps[3]);
                Count1 = Convert.ToInt32(ps[4]);
                MarkID2 = Convert.ToInt32(ps[5]);
                Count2 = Convert.ToInt32(ps[6]);
                content = ps[7];
                return true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("RVStaus Parse " + ex.Message);
                return false;
            }
        }

        public RVStatus Clone()
		{
            RVStatus n = new RVStatus(_str_cmd);
            n.content = content;
            n._seq = _seq;
            n.SiteID = SiteID;
            n.MarkID1 = MarkID1;
            n.Count1 = Count1;
            n.MarkID2 = MarkID2;
            n.Count2 = Count2;
            return n;
        }
	}
}
